package standard.util;

import standard.ColumnInfo;
import standard.StandardVar;

/**
 * Create by Lingo
 */

public class Utils {

    public static StandardVar colInfo2StandardVar(ColumnInfo columnInfo){
        StandardVar var = new StandardVar();
        String javaClassName = columnInfo.getJavaClassName();
        var.setType(handleClassName(javaClassName));
        var.setApiModelProperty(columnInfo.getRemark());
        var.setColName(columnInfo.getName());
        var.setIsNullable(columnInfo.getIsNullable());
        var.setIsPrimary(columnInfo.getIsPrimary());
        return var;
    }

    public static String tableName2ModelName(String colName){
        if (colName.startsWith("t_bb")){
            colName = colName.replace("t_bb_", "");
        }
        String varName = "";
        int i = 0;
        while ((i = colName.indexOf("_",i+1)) != -1) {
            varName = colName.substring(0,i)+Character.toUpperCase(colName.charAt(i+1))+colName.substring(i+2);
        }
        return varName;
    }

    public static String colName2VarName(String colName) {
        String temp =  colName.toLowerCase();
        int i = 0;
        while ((i= temp.indexOf('_'))!=-1){
            temp = temp.substring(0,i)+Character.toUpperCase(temp.charAt(i+1))+temp.substring(i+2);
        }
        return temp;
    }

    public static void main(String[] args) {
        System.out.println(colName2VarName("forigin_chn_name"));
    }
    /**
     * 将类型从全限定模式改成精简模式
     * @param limitedClassName
     * @return
     */
    public static String handleClassName(String limitedClassName){
        String className = limitedClassName.substring(limitedClassName.lastIndexOf(".")+1);
        return className;
    }

}
